package vn.fpt.fsoft.action.user;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.struts.ActionSupport;

import vn.fpt.fsoft.bl.UserBo;
import vn.fpt.fsoft.entity.User;
import vn.fpt.fsoft.user.form.UserForm;

 
public class AddUserAction extends ActionSupport{
 
	public ActionForward execute(ActionMapping mapping,ActionForm form,
		HttpServletRequest request,HttpServletResponse response) 
        throws Exception {
		try {
			UserBo UserBo =
				(UserBo) getWebApplicationContext().getBean("userBo");
			
			UserForm UserForm = (UserForm)form;
			User User = new User();
			
			//copy Userform to model
			BeanUtils.copyProperties(User, UserForm);
			
			//save it
			UserBo.addUser(User);
		        
			return mapping.findForward("success");
		} catch (Exception e) {
			return mapping.findForward("false");
		}
 
	}
 
}